#include "http_server_diagnosis.h"

#include <algorithm>
#include <future>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>

#include "utils_file_ex.h"
#include "utils_string_ex.h"
#include "utils_string_ex.h"
#include "utils_log.h"
#include "common_shell.h"
#include "http_server_impl.h"

namespace El {
namespace WebServer {

HttpServerDiagnosis &HttpServerDiagnosis::GetInstance()
{
    static HttpServerDiagnosis instance;
    return instance;
}

bool HttpServerDiagnosis::Start()
{
    Common::Shell::GetInstance().RegisterCommand(
        "web", std::bind(&HttpServerDiagnosis::Protocol, this, std::placeholders::_1));
    return true;
}

void HttpServerDiagnosis::Protocol(const std::string &args)
{
    std::vector<std::string> vec_args;
    Utils::Split(args, " ", vec_args);
    if (vec_args.size() < 1) {
        EL_ERROR("Invalid args: {}", args.c_str());
        return;
    }

    if (vec_args[0] == "tokens") {
        HttpServerImpl::GetInstance().PrintBearerTokens();
        return;
    }

    EL_ERROR("Unknown command: {}", vec_args[0]);
}

} // namespace WebServer
} // namespace El